//
//  NSMatchHeaderView.m
//  Meboo
//
//  Created by kyo on 2024/5/13.
//

#import "NSMatchHeaderView.h"

@interface NSMatchHeaderView ()
//左侧背景图
@property (nonatomic, strong) UIImageView *leftImageView;
//右侧背景图
@property (nonatomic, strong) UIImageView *rightImageView;
//我的头像
@property (nonatomic, strong) UIImageView *myImageView;
//matched
@property (nonatomic, strong) UIImageView *matchImageView;
//标题
@property (nonatomic, strong) UILabel *titleLab;
@end

@implementation NSMatchHeaderView

#pragma mark - Life Cycle
- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self setupUI];
    }
    return self;
}

#pragma mark - Action

- (void)backAction {
    [self.currentViewController.navigationController popViewControllerAnimated:YES];;
}

#pragma mark - UI
- (void)setupUI {
    
    self.backgroundColor = UIColor.clearColor;
    
    [self addSubview:self.myImageView];
    [self.myImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_centerX).offset(MBWidthScale(-20));
        make.top.mas_equalTo(MBHeightScale(30));
        make.width.height.mas_equalTo(MBHeightScale(104));
    }];
    
    [self addSubview:self.modelImageView];
    [self.modelImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.mas_centerX).offset(MBWidthScale(20));
        make.top.mas_equalTo(MBHeightScale(30));
        make.width.height.mas_equalTo(MBHeightScale(104));
    }];
    
    [self addSubview:self.leftImageView];
    [self.leftImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.modelImageView.mas_left).offset(MBWidthScale(20));
        make.centerY.equalTo(self.modelImageView);
        make.height.mas_equalTo(MBHeightScale(118));
        make.width.mas_equalTo(MBHeightScale(118)*55/118);
    }];
    
    [self addSubview:self.rightImageView];
    [self.rightImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.myImageView.mas_right).offset(MBWidthScale(-20));
        make.centerY.equalTo(self.modelImageView);
        make.height.mas_equalTo(MBHeightScale(118));
        make.width.mas_equalTo(MBHeightScale(118)*55/118);
    }];
    
    [self addSubview:self.matchImageView];
    [self.matchImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.bottom.equalTo(self.leftImageView).offset(MBHeightScale(-2));
        make.height.mas_equalTo(MBHeightScale(39));
        make.width.mas_equalTo(MBHeightScale(39)*142/39);
    }];
    
    [self addSubview:self.titleLab];
    [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.bottom.equalTo(self);
        make.top.equalTo(self.leftImageView.mas_bottom);
    }];
}

#pragma mark - Setter && Getter

- (UILabel *)titleLab {
    if (!_titleLab) {
        _titleLab = [[UILabel alloc] init];
        _titleLab.textAlignment = NSTextAlignmentCenter;
        _titleLab.text = @"✨  Your crush likes you back  ✨";
        _titleLab.font = MBHelBoldFontSizeScale(15);
        _titleLab.textColor = HEXS(@"DF3B78");
    }
    return _titleLab;
}

- (UIImageView *)leftImageView {
    if (!_leftImageView) {
        _leftImageView = [UIImageView new];
        _leftImageView.image = ImageWithName(@"chat_match_back_left");
    }
    return _leftImageView;
}

- (UIImageView *)rightImageView {
    if (!_rightImageView) {
        _rightImageView = [UIImageView new];
        _rightImageView.image = ImageWithName(@"chat_match_back_right");
    }
    return _rightImageView;
}

- (UIImageView *)modelImageView {
    if (!_modelImageView) {
        _modelImageView = [UIImageView new];
        _modelImageView.image = ImageWithName(@"flower_defult");
        _modelImageView.contentMode = UIViewContentModeScaleAspectFill;
        _modelImageView.layer.cornerRadius = MBHeightScale(104/2);
        _modelImageView.layer.borderColor = HEXS(@"B92176").CGColor;
        _modelImageView.layer.borderWidth = 2;
        _modelImageView.layer.masksToBounds = YES;
    }
    return _modelImageView;
}

- (UIImageView *)myImageView {
    if (!_myImageView) {
        _myImageView = [UIImageView new];
        [_myImageView sd_setImageWithURL:[NSURL URLWithString:[MBUserAccount defaultAccount].avatarUrl]];
        _myImageView.contentMode = UIViewContentModeScaleAspectFill;
        _myImageView.layer.cornerRadius = MBHeightScale(104/2);
        _myImageView.layer.borderColor = HEXS(@"B92176").CGColor;
        _myImageView.layer.borderWidth = 2;
        _myImageView.layer.masksToBounds = YES;
    }
    return _myImageView;
}

- (UIImageView *)matchImageView {
    if (!_matchImageView) {
        _matchImageView = [UIImageView new];
        _matchImageView.image = ImageWithName(@"chat_match_matched");
    }
    return _matchImageView;
}
@end
